<?php

class Model_Report extends PhalApi_Model_NotORM {

    public function  getByCol($width, $height, $devicePixelRatio) {
        return $this->getORM()
            ->select('id')
            ->where('width = ? and height = ? and devicePixelRatio = ?', $width, $height, $devicePixelRatio)
            ->fetch();

    }

    public function timesUpdateById($id) {
        return $this->getORM()
            ->where('id = ?', $id)
            ->update(['times' => new NotORM_Literal("times + 1")]);
    }

    public function insertRow($width, $height, $devicePixelRatio, $ua) {
        return $this->getORM()
            ->insert([
                "width"            => $width,
                "height"           => $height,
                "devicePixelRatio" => $devicePixelRatio,
                "ua"               => $ua,
            ]);
    }

    public function getlist() {
        return $this->getORM()
            ->select("width,height,devicePixelRatio,ua,times")
            ->order("times desc")
            ->fetchRows();
    }

    protected function getTableName($id) {
        return 'reports';
    }
}
